package com.yun.util;

import javax.mail.MessagingException;
import java.util.List;

//邮件处理器  smtp协议
public class EmailSmtp {

    /**
     * 邮箱发送
     * @param ssl               端口
     * @param emailhost         主机
     * @param emailUser         发送用户
     * @param emailPwd         授权密码
     * @param mailRecipientList         接收用户集合
     * @param title         标题
     * @param content       内容
     * @param attachmentFilePath  附件
     * @throws Exception  异常
     */
    public static void sendMail(String ssl,String emailhost,String emailUser,String emailPwd,List<String> mailRecipientList,String title, String content,String attachmentFilePath) throws Exception {
        if (emailhost == null) {
            throw new MessagingException("系统邮箱 SMTP 主机未设置");
        }
        if (isEmpty(emailUser) || isEmpty(emailPwd)) {
            throw new MessagingException("系统邮箱未设置");
        }
        if (mailRecipientList==null) {
            throw new MessagingException("收件人 未设置");
        }
        MailUtil.send(emailhost, emailUser, emailPwd, title, content, "态势感知平台", mailRecipientList, "true".equals(ssl), attachmentFilePath);
    }

    public static boolean isEmpty(String str) {
        return str == null || str.isEmpty();
    }
}
